<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${ctxPath}/static/layui/css/layui.css" />
	<title>用户登录</title>
	<script src="${ctxPath}/static/layui/layui.js"></script>
	<script src="${ctxPath}/static/js/jquery-3.6.1.min.js"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title"
		  style="margin-top: 20px;">
	<legend>审批页</legend>
</fieldset>

<form id="frmLeave" lass="layui-form">

	<div class="layui-form-item">
		<label class="layui-form-label">发起人:</label>
		<div class="layui-input-block" style="width:450px;">
			<input type="text"  autocomplete="off" id="initiatorName"
				   value="${leave.initiatorName}" readonly class="layui-input">
		</div>
	</div>


	<div class="layui-form-item">
		<label class="layui-form-label">开始时间:</label>
		<div class="layui-input-block" style="width:450px;">
			<input type="text"  autocomplete="off" id="startDate"
				   value="${leave.initiatorName}" readonly class="layui-input">
		</div>
	</div>


	<div class="layui-form-item">
		<label class="layui-form-label">结束时间:</label>
		<div class="layui-input-block" style="width:450px;">
			<input type="text"  autocomplete="off" id="endDate"
				   value="${leave.endDate}" readonly class="layui-input">
		</div>
	</div>



	<div class="layui-form-item">
		<label class="layui-form-label">请假类型:</label>
		<div class="layui-input-block" style="width:450px;">
			<input type="text"  autocomplete="off" id="leaveType"
				   value="${leave.leaveType}" readonly class="layui-input">
		</div>
	</div>



	<div class="layui-form-item">
		<label class="layui-form-label">请假原因:</label>
		<div class="layui-input-block" style="width:450px;">
			<input type="text"  autocomplete="off" id="reason"
				   value="${leave.reason}" readonly class="layui-input">
		</div>
	</div>
	<br/>



<%--	<label>拒绝原因:</label>--%>
<%--	<textarea id="refuseReason"></textarea>--%>

	<div class="layui-form-item">
		<label class="layui-form-label">拒绝原因:</label>
		<div class="layui-input-block" style="width:450px;">
			<textarea id="refuseReason"  class="layui-textarea"></textarea>
		</div>
	</div>

	<br/><br/>


	<div class="layui-form-item">
		<label class="layui-form-label">任务 ID:</label>
		<div class="layui-input-block" style="width:450px;">
			<input type="text"  autocomplete="off" id="taskId"
				   value="${leave.taskId}" readonly class="layui-input">
		</div>
	</div>
	<br/><br/>


	<div class="layui-form-item">
		<div class="layui-input-block">
			<button type="button" class="layui-btn" onclick="apprLeave('true');">同意申请</button>
			<button type="button" class="layui-btn" onclick="apprLeave('false');">拒绝申请</button>
		</div>
	</div><br/><br/>

</form>

<script>
function apprLeave( _flag ){
	var _taskId = $("#taskId").val();
	//{1}当前用户的部门 Id
	var _deptId = '${user.dept.id}';
	//{2}拒绝原因
	var _reason = $("#refuseReason").val();
	//{3}提交地址
	$.ajax(
		{
			url:'${ctxPath}/Leave/doApprove',
			type:'post',
			data:{
				deptId:_deptId,
				appFlag:_flag,
				refuseReason:_reason,
				taskId:_taskId
			},
			dataType:"json",
			success:function( json ){
				console.log( json );
				var ret = json['result'];
				if( ret=='success' ){
					alert('提交审批成功。');
					window.location = "${ctxPath}/Leave/waitMyApprove";
				}else{
					var cause = json['cause'];
					alert('提交审批失败, 原因:'+ cause);
				}
			}
		}		
	);
}
</script>

</body>
</html>
